package com.gaozhaoyang.servlet;

import com.gaozhaoyang.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

@WebServlet("/h1")
public class MyServlet_01  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("msg","我是保存的字符串内容");
        User user = new User(1001,"pgong","hahah");

        HashMap<String, String> map = new HashMap<>();
        map.put("it001", "张三");
        map.put("it002", "李四");

        HashMap<String, User> hmap = new HashMap<>();

        hmap.put("ujiuye1", new User(1002, "lxl", "小鲜肉"));
        hmap.put("ujiuye2",new User(1003,"马蓉","帮助别人快乐自己"));

        ArrayList<String> list = new ArrayList<>();
        list.add("孙悟空");
        list.add("猪八戒");
        list.add("白骨精");

        int arr[] ={11,12,13};
        req.setAttribute("arr",arr);

        req.setAttribute("list",list);

        ArrayList<User> users = new ArrayList<>();

        users.add(new User(1001, "大象", "戏水"));
        users.add(new User(1002, "穿山甲", "喝鸡汤"));

        req.setAttribute("ulist", users);


        req.setAttribute("hmap",hmap);

        req.setAttribute("m1",map);

        req.setAttribute("u1",user);
        req.getRequestDispatcher("/jsp/jsp_demo20.jsp").forward(req,resp);
    }
}
